package com.dily.study.user.controller;

import com.dily.scaffold.common.reponse.BaseResponse;
import com.dily.study.user.entity.User;
import com.dily.study.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Date: 2022-06-09 星期四
 * Time: 17:21
 * Author: Dily_Su
 * Remark:
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * hasAuthority 是一个方法，我们也可以自定义方法来实现权限验证
     * @de 为自定义权限验证方法的类，调用其 hasAuthority 方法进行验证
     * @return
     */
    @PreAuthorize("@de.hasAuthority('test')")
    @RequestMapping("/hello")
    public String hello(){
        return "hello";
    }

    @RequestMapping("/login")
    public BaseResponse<?> login(@RequestBody User user){
        return userService.login(user);
    }

    @RequestMapping("/logout")
    public BaseResponse<?> logout(){
        return userService.logout();
    }
}
